Track session context changes during task execution#19
Conversation
- Updated SDK to ^0.1.24 (installed 0.1.25) - Added SessionEvent import and re-export in copilot.ts - Extended StreamCallbacks with onSessionEvent callback - Modified sendPrompt to listen for all session events - Updated sendPromptSync to accept and pass session event callback - Added SessionEventWithTask type in executor.ts - Extended ExecutionCallbacks with onSessionEvent callback - Updated executeTask and init task to forward session events - Added session event tracking in execute.tsx - Display current working directory for running tasks - Show context change events in task details Co-authored-by: colindembovsky <1932561+colindembovsky@users.noreply.github.com>
- Created executor.test.ts with tests for SessionEventWithTask type - Verified context change events are correctly structured - Tested session.start events with context - Verified ExecutionCallbacks accepts optional onSessionEvent - All tests passing Co-authored-by: colindembovsky <1932561+colindembovsky@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds Copilot SDK session context tracking into Planeteer’s execution flow so the UI can show per-task working directory (and related repo metadata) and recent context-change history during execution.
Changes:
- Bumped
@github/copilot-sdkto^0.1.24and re-exportedSessionEventfromcopilot.ts. - Threaded optional
onSessionEventthroughcopilot.ts→executor.ts→execute.tsx. - Added basic unit tests around the new types/callback shape.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/services/copilot.ts |
Re-exports SessionEvent and optionally forwards session events from SDK sessions. |
src/services/executor.ts |
Introduces SessionEventWithTask and forwards session events with task IDs through ExecutionCallbacks. |
src/screens/execute.tsx |
Captures session events and renders cwd + recent context changes in the task UI. |
src/services/executor.test.ts |
Adds tests for the new type and callback optionality. |
package.json |
Updates Copilot SDK dependency range to enable context tracking support. |
package-lock.json |
Locks updated SDK (and transitive) versions. |
| const [summarized, setSummarized] = useState(''); | ||
| const [sessionEvents, setSessionEvents] = useState<SessionEventWithTask[]>([]); | ||
| const [taskContexts, setTaskContexts] = useState<Record<string, { cwd?: string; repository?: string; branch?: string }>>({}); | ||
|
|
There was a problem hiding this comment.
sessionEvents and taskContexts are kept across retries / reruns (runCount changes) and are not cleared when restarting execution. This can show stale cwd/repo/branch from a previous run or from before a task retry. Consider resetting these states when a new run starts, and clearing per-task context when retrying that task.
| useEffect(() => { | |
| // When a new execution run starts, clear any session events and per-task | |
| // contexts from previous runs to avoid showing stale cwd/repo/branch data. | |
| if (runCount === 0) { | |
| return; | |
| } | |
| setSessionEvents([]); | |
| setTaskContexts({}); | |
| }, [runCount]); |
| {context?.cwd && ( | ||
| <Box marginLeft={4}> | ||
| <Text color="cyan" dimColor>📁 {context.cwd}</Text> | ||
| {context.repository && ( | ||
| <Text color="blue" dimColor> ({context.repository})</Text> | ||
| )} |
There was a problem hiding this comment.
The task list context display omits branch even though it’s captured in taskContexts and the PR description example shows repo@branch. Consider including branch here (when present) to match the intended UI output.
| try { | ||
| const prompt = buildTaskPrompt(task, updatedPlan, codebaseContext); | ||
| const result = await sendPromptSync(EXECUTOR_SYSTEM_PROMPT, [ | ||
| { role: 'user', content: prompt }, | ||
| ], { | ||
| onDelta: (delta, fullText) => { | ||
| callbacks.onTaskDelta(task.id, delta, fullText); | ||
| }, | ||
| onSessionEvent: (event) => { | ||
| callbacks.onSessionEvent?.({ taskId: task.id, event }); | ||
| }, | ||
| }); |
There was a problem hiding this comment.
New behavior forwards onSessionEvent from sendPromptSync into ExecutionCallbacks with task context. The added tests currently only construct objects / check optionality and don’t verify that executePlan actually invokes callbacks.onSessionEvent during execution (including the init task). Please add a unit test that mocks sendPromptSync to emit a SessionEvent and asserts the callback receives { taskId, event }.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot SDK v0.1.24+ exposes
session.context_changedevents andSessionContextin session metadata. This enables tracking when agents change working directories during task execution.Changes
SDK Integration
@github/copilot-sdkto^0.1.24for context tracking supportonSessionEventcallback toStreamCallbacksincopilot.tssendPromptto listen for all session events when callback providedExecutor Layer
SessionEventWithTasktype to associate session events with task IDsExecutionCallbackswith optionalonSessionEventcallbackexecuteTaskand init task to forward session events with task contextUI Display
session.startandsession.context_changedevents📁 /workspace/path (repo@branch)Testing
SessionEventWithTasktype and callback handlingExample
When an agent changes directories during execution:
UI renders:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.